use crate::replace_fonts;
use crate::ui::home::HomeUI;
use egui::{Ui};
use lazy_static::lazy_static;
use std::cmp::PartialEq;
use std::collections::HashMap;



pub(crate) mod home;
pub(crate) mod ui_chat_msg;

// 登录

lazy_static! {
    pub static ref FULL_WIDTH: f32 = 0.0;
    pub static ref FULL_HEIGHT: f32 = 0.0;
}

pub(crate) trait PageUI {
    fn show_ui(&mut self, ui: &mut Ui, winfo: LWindowInfo);
}

pub(crate) struct RouteInfo {
    route_page: RoutePage, // 路由字段
    param: Vec<String>,
}

impl RouteInfo {
    pub(crate) fn new() -> Self {
        return RouteInfo {
            route_page: RoutePage::Home,
            param: vec![],
        };
    }

    pub(crate) fn set_route_param(&mut self, r_page: RoutePage, param: Vec<String>) {
        self.route_page = r_page;
        self.param = param;
    }
}

pub struct MyApp {
    route_info: RouteInfo,
    temp: u32,
    now_page: RoutePage,
    page_map: HashMap<RoutePage, Box<dyn PageUI>>,
    home_ui: HomeUI,
}
impl MyApp {
    pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
        replace_fonts(&cc.egui_ctx);
        Self {
            route_info: RouteInfo::new(),
            temp: 0,
            now_page: RoutePage::Home,
            page_map: HashMap::new(),
            home_ui: HomeUI::new(),
        }
    }

    pub(crate) fn set_now_page(&mut self, npage: RoutePage) {
        self.now_page = npage;
    }
}

impl eframe::App for MyApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::CentralPanel::default().show(ctx, |ui| match &self.route_info.route_page {
            RoutePage::Home => {
                let _ = &self.home_ui.show_ui(&mut self.route_info, ui);
            }
            _ => {
                let _ = &self.home_ui.show_ui(&mut self.route_info, ui);
            }
        });
    }
}

#[derive(PartialEq, Eq, Debug)]
enum RoutePage {
    Home,
}

pub(crate) struct LWindowInfo {
    pub(crate) f_width: f32,
    pub(crate) f_heigth: f32,
}
